package cn.jy.boot.controller;

import cn.jy.boot.pojo.Address;
import cn.jy.boot.pojo.Person;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Date;

@Controller
public class TestController {
    @RequestMapping("/test")
    public String test(Model model, HttpSession session){
//        在session的作用域中放入一个变量
        session.setAttribute("username","admin");
        model.addAttribute("msg","<h1>thymeleaf test</h1>");
        Person person = new Person();
        person.setId(1);
        person.setAge(20);person.setName("xiaoming");
        Address address = new Address();
        address.setHomeAddress("河北唐山");address.setSchoolAddress("山西吕梁");
        person.setAddress(address);
        person.setStudent(false);
        person.setSex(1);
        model.addAttribute("person",person);

        model.addAttribute("myDate",new Date());

        model.addAttribute("pNames",
                Arrays.asList("zhangsan","lisi","wangwu","zhaoliu","hahaha","goudan"));
        return "test";
    }

}
